package com.sparsearr.datastructures.itheima.dafen;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Scanner;

/**
 * @Author: ZhaoTR
 * @Date: Created in 2025/4/19 16:45
 * @Description: 评委打分
 * @Version: 1.0
 */

public class DaScore {
    private static final Logger logger = LogManager.getLogger(DaScore.class);

    public static void main(String[] args) {
        int[] scoreArr = getScore();
        for (int i = 0; i < scoreArr.length; i++) {
            System.out.println("第" + (i + 1) + "个评委打分：" + scoreArr[i]);
        }

        int max = getMax(scoreArr);
        int min = getMin(scoreArr);
        int sum = getSum(scoreArr);

        int avg = (sum - max - min) / (scoreArr.length - 2);
        logger.info("平均分：{}", avg);
    }

    private static int getSum(int[] scoreArr) {
        int sum = 0;
        for (int i = 0; i < scoreArr.length; i++) {
            sum += scoreArr[i];
        }
        return sum;
    }

    private static int getMax(int[] scoreArr) {
        int max = scoreArr[0];
        for (int i = 0; i < scoreArr.length; i++) {
            if (scoreArr[i] > max) ;
        }
        return max;
    }

    private static int getMin(int[] scoreArr) {
        int min = scoreArr[0];
        for (int i = 0; i < scoreArr.length; i++) {
            if (scoreArr[i] < min) ;
        }
        return min;
    }


    private static int[] getScore() {
        int[] scores = new int[6];
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入评委打分");
        for (int i = 0; i < scores.length; ) {
            int score = scanner.nextInt();
            if (score >= 0 && score <= 100) {
                scores[i] = score;
                i++;
            } else {
                System.out.println("输入有误，请重新输入");
            }
        }
        return scores;
    }
}
